package com.chinanet.netelementmodel;


import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.webservice.AttrsIn;
import com.chinanet.utils.webservice.WebService;

import java.util.HashMap;
import java.util.Map;


/**
 * 10000_CRM_GETBSTINFO
 * CRM根据号码查询百事通卡信息
 * @author xuzhi
 *
 */
public class CRM_WebService_Imp_10000_CRM_GETBSTINFO implements WorkInterFace {

	@Override
	public String getName() {
		return "CRM根据号码查询百事通卡信息";
	}

	@Override
	public String getDesciption() {
		return "";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in=new Attr[1];
		in[0]=new Attr("DN","C网手机号码", AttrType.TYPE_String,true);
//		in[1]=new Attr("CITY","CITY:地市标识(0570:衢州；0571:杭州；0572:湖州；0573:嘉兴；0574:宁波；0575:绍兴；0576:台州；0577:温州；0578:丽水；0579:金华；0580:舟山)",AttrType.TYPE_String,true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[5];
		out[0]=new Attr("ReturnCode", "0：成功；其它：失败", AttrType.TYPE_Int, true);
		out[1]=new Attr("Report", "返回report", AttrType.TYPE_String, true);
		out[2]=new Attr("log", "服务器返回的soapxml", AttrType.TYPE_String, true);
		out[3]=new Attr("Errormsg", "服务器返回的错误信息,当ReturnCode为0的时候就不必去读取", AttrType.TYPE_String, false);
		out[4]=new Attr("flag","执行成功是1，失败是0",AttrType.TYPE_Int,true);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		AttrsIn attrsIn=new AttrsIn();
		WebService webService=new WebService();
		Map<String,Object> map=new HashMap<String, Object>();
		//Get into arguments
		attrsIn.setClientSysName("CDMA");
		attrsIn.setFunctionName("getBstInfo");
		attrsIn.setRequestMessage("<NETACTION_NAME>查询百事通信息</NETACTION_NAME><CITY>0576</CITY><DN>"+(String) data.get("DN")+"</DN>");
		//Get soapxml
		String returnXml=webService.WebServiceInit(attrsIn);
		String flag=webService.getPattern("flag", returnXml);
		if(flag.equals("true")){
			map.put("ReturnCode", 0);
			map.put("Report", webService.getPattern("Report", returnXml));
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "");
			map.put("flag",1);
		}else{
			map.put("flag",0);
			map.put("ReturnCode", 1);
			map.put("Report", "");
			map.put("log", webService.dealkouhao(returnXml));
			map.put("Errormsg", "网元侧执行出错，处理请求失败");
		}
		
		return map;
	}

}
